1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module glib.DateTime; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import glib.TimeVal; 30 private import glib.TimeZone; 31 private import glib.c.functions; 32 public import glib.c.types; 33 private import linker.Loader; 34 35 36 /** 37 * An opaque structure that represents a date and time, including a time zone. 38 * 39 * Since: 2.26 40 */ 41 public class DateTime 42 { 43 /** the main Gtk struct */ 44 protected GDateTime* gDateTime; 45 protected bool ownedRef; 46 47 /** Get the main Gtk struct */ 48 public GDateTime* getDateTimeStruct(bool transferOwnership = false) 49 { 50 if (transferOwnership) 51 ownedRef = false; 52 return gDateTime; 53 } 54 55 /** the main Gtk struct as a void* */ 56 protected void* getStruct() 57 { 58 return cast(void*)gDateTime; 59 } 60 61 /** 62 * Sets our main struct and passes it to the parent class. 63 */ 64 public this (GDateTime* gDateTime, bool ownedRef = false) 65 { 66 this.gDateTime = gDateTime; 67 this.ownedRef = ownedRef; 68 } 69 70 ~this () 71 { 72 if ( Linker.isLoaded(LIBRARY_GLIB[0]) && ownedRef ) 73 g_date_time_unref(gDateTime); 74 } 75 76 /** 77 * Creates a DateTime corresponding to the given Unix time t 78 * Unix time is the number of seconds that have elapsed since 1970-01-01 79 * 00:00:00 UTC, regardless of the local time offset. 80 * 81 * This call can fail (ConstructionException) if t represents a time outside 82 * of the supported range of GDateTime. 83 * You should release the return value by calling unref() 84 * when you are done with it 85 * 86 * Params: 87 * t = the Unix time 88 * utc = If true use utc else use the local timezone. 89 * 90 * Throws: ConstructionException GTK+ fails to create the object. 91 * 92 * Since: 2.26 93 */ 94 public this (long t, bool utc = true) 95 { 96 GDateTime* p; 97 98 if ( utc ) 99 { 100 p = g_date_time_new_from_unix_utc(t); 101 } 102 else 103 { 104 p = g_date_time_new_from_unix_local(t); 105 } 106 107 if(p is null) 108 { 109 throw new ConstructionException("null returned by g_date_time_new_from_unix_local(t)"); 110 } 111 this(cast(GDateTime*) p); 112 } 113 114 /** 115 * Creates a DateTime corresponding to the given TimeVal tv. 116 * The time contained in a TimeVal is always stored in the form of 117 * seconds elapsed since 1970-01-01 00:00:00 UTC, regardless of the 118 * local time offset. 119 * 120 * This call can fail (ConstructionException) if tv represents a time outside 121 * of the supported range of DateTime. 122 * You should release the return value by calling unref() 123 * when you are done with it. 124 * 125 * Params: 126 * tv = a GTimeVal 127 * utc = If true use utc else use the local timezone. 128 * 129 * Throws: ConstructionException GTK+ fails to create the object. 130 * 131 * Since: 2.26 132 */ 133 public this (ref GTimeVal tv, bool utc = true) 134 { 135 GDateTime* p; 136 137 if ( utc ) 138 { 139 p = g_date_time_new_from_timeval_utc(&tv); 140 } 141 else 142 { 143 p = g_date_time_new_from_timeval_local(&tv); 144 } 145 146 if(p is null) 147 { 148 throw new ConstructionException("null returned by g_date_time_new_from_timeval_local((tv is null) ? null : tv.getTimeValStruct())"); 149 } 150 this(cast(GDateTime*) p); 151 } 152 153 /** */ 154 override bool opEquals(Object rhs) 155 { 156 DateTime date = cast(DateTime)rhs; 157 158 if ( date is null ) 159 return false; 160 161 return equal(date) != 0; 162 } 163 164 /** */ 165 override int opCmp(Object rhs) 166 { 167 DateTime date = cast(DateTime)rhs; 168 169 if ( date is null ) 170 return int.min; 171 172 return compare(date); 173 } 174 175 /** */ 176 override nothrow @trusted hash_t toHash() 177 { 178 return hash(); 179 } 180 181 /** 182 * Hashes datetime into a guint, suitable for use within GHashTable. 183 * Since 2.26 184 * Params: 185 * datetime = a GDateTime 186 * Returns: a guint containing the hash 187 */ 188 public nothrow @trusted uint hash() 189 { 190 try 191 { 192 return g_date_time_hash(gDateTime); 193 } 194 catch(Exception e) 195 { 196 return 0; 197 } 198 } 199 200 /** 201 */ 202 203 /** 204 * Creates a new #GDateTime corresponding to the given date and time in 205 * the time zone @tz. 206 * 207 * The @year must be between 1 and 9999, @month between 1 and 12 and @day 208 * between 1 and 28, 29, 30 or 31 depending on the month and the year. 209 * 210 * @hour must be between 0 and 23 and @minute must be between 0 and 59. 211 * 212 * @seconds must be at least 0.0 and must be strictly less than 60.0. 213 * It will be rounded down to the nearest microsecond. 214 * 215 * If the given time is not representable in the given time zone (for 216 * example, 02:30 on March 14th 2010 in Toronto, due to daylight savings 217 * time) then the time will be rounded up to the nearest existing time 218 * (in this case, 03:00). If this matters to you then you should verify 219 * the return value for containing the same as the numbers you gave. 220 * 221 * In the case that the given time is ambiguous in the given time zone 222 * (for example, 01:30 on November 7th 2010 in Toronto, due to daylight 223 * savings time) then the time falling within standard (ie: 224 * non-daylight) time is taken. 225 * 226 * It not considered a programmer error for the values to this function 227 * to be out of range, but in the case that they are, the function will 228 * return %NULL. 229 * 230 * You should release the return value by calling g_date_time_unref() 231 * when you are done with it. 232 * 233 * Params: 234 * tz = a #GTimeZone 235 * year = the year component of the date 236 * month = the month component of the date 237 * day = the day component of the date 238 * hour = the hour component of the date 239 * minute = the minute component of the date 240 * seconds = the number of seconds past the minute 241 * 242 * Returns: a new #GDateTime, or %NULL 243 * 244 * Since: 2.26 245 * 246 * Throws: ConstructionException GTK+ fails to create the object. 247 */ 248 public this(TimeZone tz, int year, int month, int day, int hour, int minute, double seconds) 249 { 250 auto __p = g_date_time_new((tz is null) ? null : tz.getTimeZoneStruct(), year, month, day, hour, minute, seconds); 251 252 if(__p is null) 253 { 254 throw new ConstructionException("null returned by new"); 255 } 256 257 this(cast(GDateTime*) __p); 258 } 259 260 /** 261 * Creates a #GDateTime corresponding to the given 262 * [ISO 8601 formatted string](https://en.wikipedia.org/wiki/ISO_8601) 263 * @text. ISO 8601 strings of the form <date><sep><time><tz> are supported, with 264 * some extensions from [RFC 3339](https://tools.ietf.org/html/rfc3339) as 265 * mentioned below. 266 * 267 * Note that as #GDateTime "is oblivious to leap seconds", leap seconds information 268 * in an ISO-8601 string will be ignored, so a `23:59:60` time would be parsed as 269 * `23:59:59`. 270 * 271 * <sep> is the separator and can be either 'T', 't' or ' '. The latter two 272 * separators are an extension from 273 * [RFC 3339](https://tools.ietf.org/html/rfc3339#section-5.6). 274 * 275 * <date> is in the form: 276 * 277 * - `YYYY-MM-DD` - Year/month/day, e.g. 2016-08-24. 278 * - `YYYYMMDD` - Same as above without dividers. 279 * - `YYYY-DDD` - Ordinal day where DDD is from 001 to 366, e.g. 2016-237. 280 * - `YYYYDDD` - Same as above without dividers. 281 * - `YYYY-Www-D` - Week day where ww is from 01 to 52 and D from 1-7, 282 * e.g. 2016-W34-3. 283 * - `YYYYWwwD` - Same as above without dividers. 284 * 285 * <time> is in the form: 286 * 287 * - `hh:mm:ss(.sss)` - Hours, minutes, seconds (subseconds), e.g. 22:10:42.123. 288 * - `hhmmss(.sss)` - Same as above without dividers. 289 * 290 * <tz> is an optional timezone suffix of the form: 291 * 292 * - `Z` - UTC. 293 * - `+hh:mm` or `-hh:mm` - Offset from UTC in hours and minutes, e.g. +12:00. 294 * - `+hh` or `-hh` - Offset from UTC in hours, e.g. +12. 295 * 296 * If the timezone is not provided in @text it must be provided in @default_tz 297 * (this field is otherwise ignored). 298 * 299 * This call can fail (returning %NULL) if @text is not a valid ISO 8601 300 * formatted string. 301 * 302 * You should release the return value by calling g_date_time_unref() 303 * when you are done with it. 304 * 305 * Params: 306 * text = an ISO 8601 formatted time string. 307 * defaultTz = a #GTimeZone to use if the text doesn't contain a 308 * timezone, or %NULL. 309 * 310 * Returns: a new #GDateTime, or %NULL 311 * 312 * Since: 2.56 313 * 314 * Throws: ConstructionException GTK+ fails to create the object. 315 */ 316 public this(string text, TimeZone defaultTz) 317 { 318 auto __p = g_date_time_new_from_iso8601(Str.toStringz(text), (defaultTz is null) ? null : defaultTz.getTimeZoneStruct()); 319 320 if(__p is null) 321 { 322 throw new ConstructionException("null returned by new_from_iso8601"); 323 } 324 325 this(cast(GDateTime*) __p); 326 } 327 328 /** 329 * Creates a #GDateTime corresponding to this exact instant in the given 330 * time zone @tz. The time is as accurate as the system allows, to a 331 * maximum accuracy of 1 microsecond. 332 * 333 * This function will always succeed unless GLib is still being used after the 334 * year 9999. 335 * 336 * You should release the return value by calling g_date_time_unref() 337 * when you are done with it. 338 * 339 * Params: 340 * tz = a #GTimeZone 341 * 342 * Returns: a new #GDateTime, or %NULL 343 * 344 * Since: 2.26 345 * 346 * Throws: ConstructionException GTK+ fails to create the object. 347 */ 348 public this(TimeZone tz) 349 { 350 auto __p = g_date_time_new_now((tz is null) ? null : tz.getTimeZoneStruct()); 351 352 if(__p is null) 353 { 354 throw new ConstructionException("null returned by new_now"); 355 } 356 357 this(cast(GDateTime*) __p); 358 } 359 360 /** 361 * Creates a copy of @datetime and adds the specified timespan to the copy. 362 * 363 * Params: 364 * timespan = a #GTimeSpan 365 * 366 * Returns: the newly created #GDateTime which 367 * should be freed with g_date_time_unref(), or %NULL 368 * 369 * Since: 2.26 370 */ 371 public DateTime add(GTimeSpan timespan) 372 { 373 auto __p = g_date_time_add(gDateTime, timespan); 374 375 if(__p is null) 376 { 377 return null; 378 } 379 380 return new DateTime(cast(GDateTime*) __p, true); 381 } 382 383 /** 384 * Creates a copy of @datetime and adds the specified number of days to the 385 * copy. Add negative values to subtract days. 386 * 387 * Params: 388 * days = the number of days 389 * 390 * Returns: the newly created #GDateTime which 391 * should be freed with g_date_time_unref(), or %NULL 392 * 393 * Since: 2.26 394 */ 395 public DateTime addDays(int days) 396 { 397 auto __p = g_date_time_add_days(gDateTime, days); 398 399 if(__p is null) 400 { 401 return null; 402 } 403 404 return new DateTime(cast(GDateTime*) __p, true); 405 } 406 407 /** 408 * Creates a new #GDateTime adding the specified values to the current date and 409 * time in @datetime. Add negative values to subtract. 410 * 411 * Params: 412 * years = the number of years to add 413 * months = the number of months to add 414 * days = the number of days to add 415 * hours = the number of hours to add 416 * minutes = the number of minutes to add 417 * seconds = the number of seconds to add 418 * 419 * Returns: the newly created #GDateTime which 420 * should be freed with g_date_time_unref(), or %NULL 421 * 422 * Since: 2.26 423 */ 424 public DateTime addFull(int years, int months, int days, int hours, int minutes, double seconds) 425 { 426 auto __p = g_date_time_add_full(gDateTime, years, months, days, hours, minutes, seconds); 427 428 if(__p is null) 429 { 430 return null; 431 } 432 433 return new DateTime(cast(GDateTime*) __p, true); 434 } 435 436 /** 437 * Creates a copy of @datetime and adds the specified number of hours. 438 * Add negative values to subtract hours. 439 * 440 * Params: 441 * hours = the number of hours to add 442 * 443 * Returns: the newly created #GDateTime which 444 * should be freed with g_date_time_unref(), or %NULL 445 * 446 * Since: 2.26 447 */ 448 public DateTime addHours(int hours) 449 { 450 auto __p = g_date_time_add_hours(gDateTime, hours); 451 452 if(__p is null) 453 { 454 return null; 455 } 456 457 return new DateTime(cast(GDateTime*) __p, true); 458 } 459 460 /** 461 * Creates a copy of @datetime adding the specified number of minutes. 462 * Add negative values to subtract minutes. 463 * 464 * Params: 465 * minutes = the number of minutes to add 466 * 467 * Returns: the newly created #GDateTime which 468 * should be freed with g_date_time_unref(), or %NULL 469 * 470 * Since: 2.26 471 */ 472 public DateTime addMinutes(int minutes) 473 { 474 auto __p = g_date_time_add_minutes(gDateTime, minutes); 475 476 if(__p is null) 477 { 478 return null; 479 } 480 481 return new DateTime(cast(GDateTime*) __p, true); 482 } 483 484 /** 485 * Creates a copy of @datetime and adds the specified number of months to the 486 * copy. Add negative values to subtract months. 487 * 488 * The day of the month of the resulting #GDateTime is clamped to the number 489 * of days in the updated calendar month. For example, if adding 1 month to 490 * 31st January 2018, the result would be 28th February 2018. In 2020 (a leap 491 * year), the result would be 29th February. 492 * 493 * Params: 494 * months = the number of months 495 * 496 * Returns: the newly created #GDateTime which 497 * should be freed with g_date_time_unref(), or %NULL 498 * 499 * Since: 2.26 500 */ 501 public DateTime addMonths(int months) 502 { 503 auto __p = g_date_time_add_months(gDateTime, months); 504 505 if(__p is null) 506 { 507 return null; 508 } 509 510 return new DateTime(cast(GDateTime*) __p, true); 511 } 512 513 /** 514 * Creates a copy of @datetime and adds the specified number of seconds. 515 * Add negative values to subtract seconds. 516 * 517 * Params: 518 * seconds = the number of seconds to add 519 * 520 * Returns: the newly created #GDateTime which 521 * should be freed with g_date_time_unref(), or %NULL 522 * 523 * Since: 2.26 524 */ 525 public DateTime addSeconds(double seconds) 526 { 527 auto __p = g_date_time_add_seconds(gDateTime, seconds); 528 529 if(__p is null) 530 { 531 return null; 532 } 533 534 return new DateTime(cast(GDateTime*) __p, true); 535 } 536 537 /** 538 * Creates a copy of @datetime and adds the specified number of weeks to the 539 * copy. Add negative values to subtract weeks. 540 * 541 * Params: 542 * weeks = the number of weeks 543 * 544 * Returns: the newly created #GDateTime which 545 * should be freed with g_date_time_unref(), or %NULL 546 * 547 * Since: 2.26 548 */ 549 public DateTime addWeeks(int weeks) 550 { 551 auto __p = g_date_time_add_weeks(gDateTime, weeks); 552 553 if(__p is null) 554 { 555 return null; 556 } 557 558 return new DateTime(cast(GDateTime*) __p, true); 559 } 560 561 /** 562 * Creates a copy of @datetime and adds the specified number of years to the 563 * copy. Add negative values to subtract years. 564 * 565 * As with g_date_time_add_months(), if the resulting date would be 29th 566 * February on a non-leap year, the day will be clamped to 28th February. 567 * 568 * Params: 569 * years = the number of years 570 * 571 * Returns: the newly created #GDateTime which 572 * should be freed with g_date_time_unref(), or %NULL 573 * 574 * Since: 2.26 575 */ 576 public DateTime addYears(int years) 577 { 578 auto __p = g_date_time_add_years(gDateTime, years); 579 580 if(__p is null) 581 { 582 return null; 583 } 584 585 return new DateTime(cast(GDateTime*) __p, true); 586 } 587 588 /** 589 * A comparison function for #GDateTimes that is suitable 590 * as a #GCompareFunc. Both #GDateTimes must be non-%NULL. 591 * 592 * Params: 593 * dt2 = second #GDateTime to compare 594 * 595 * Returns: -1, 0 or 1 if @dt1 is less than, equal to or greater 596 * than @dt2. 597 * 598 * Since: 2.26 599 */ 600 public int compare(DateTime dt2) 601 { 602 return g_date_time_compare(gDateTime, (dt2 is null) ? null : dt2.getDateTimeStruct()); 603 } 604 605 /** 606 * Calculates the difference in time between @end and @begin. The 607 * #GTimeSpan that is returned is effectively @end - @begin (ie: 608 * positive if the first parameter is larger). 609 * 610 * Params: 611 * begin = a #GDateTime 612 * 613 * Returns: the difference between the two #GDateTime, as a time 614 * span expressed in microseconds. 615 * 616 * Since: 2.26 617 */ 618 public GTimeSpan difference(DateTime begin) 619 { 620 return g_date_time_difference(gDateTime, (begin is null) ? null : begin.getDateTimeStruct()); 621 } 622 623 /** 624 * Checks to see if @dt1 and @dt2 are equal. 625 * 626 * Equal here means that they represent the same moment after converting 627 * them to the same time zone. 628 * 629 * Params: 630 * dt2 = a #GDateTime 631 * 632 * Returns: %TRUE if @dt1 and @dt2 are equal 633 * 634 * Since: 2.26 635 */ 636 public bool equal(DateTime dt2) 637 { 638 return g_date_time_equal(gDateTime, (dt2 is null) ? null : dt2.getDateTimeStruct()) != 0; 639 } 640 641 /** 642 * Creates a newly allocated string representing the requested @format. 643 * 644 * The format strings understood by this function are a subset of the 645 * strftime() format language as specified by C99. The \%D, \%U and \%W 646 * conversions are not supported, nor is the 'E' modifier. The GNU 647 * extensions \%k, \%l, \%s and \%P are supported, however, as are the 648 * '0', '_' and '-' modifiers. The Python extension \%f is also supported. 649 * 650 * In contrast to strftime(), this function always produces a UTF-8 651 * string, regardless of the current locale. Note that the rendering of 652 * many formats is locale-dependent and may not match the strftime() 653 * output exactly. 654 * 655 * The following format specifiers are supported: 656 * 657 * - \%a: the abbreviated weekday name according to the current locale 658 * - \%A: the full weekday name according to the current locale 659 * - \%b: the abbreviated month name according to the current locale 660 * - \%B: the full month name according to the current locale 661 * - \%c: the preferred date and time representation for the current locale 662 * - \%C: the century number (year/100) as a 2-digit integer (00-99) 663 * - \%d: the day of the month as a decimal number (range 01 to 31) 664 * - \%e: the day of the month as a decimal number (range 1 to 31) 665 * - \%F: equivalent to `%Y-%m-%d` (the ISO 8601 date format) 666 * - \%g: the last two digits of the ISO 8601 week-based year as a 667 * decimal number (00-99). This works well with \%V and \%u. 668 * - \%G: the ISO 8601 week-based year as a decimal number. This works 669 * well with \%V and \%u. 670 * - \%h: equivalent to \%b 671 * - \%H: the hour as a decimal number using a 24-hour clock (range 00 to 23) 672 * - \%I: the hour as a decimal number using a 12-hour clock (range 01 to 12) 673 * - \%j: the day of the year as a decimal number (range 001 to 366) 674 * - \%k: the hour (24-hour clock) as a decimal number (range 0 to 23); 675 * single digits are preceded by a blank 676 * - \%l: the hour (12-hour clock) as a decimal number (range 1 to 12); 677 * single digits are preceded by a blank 678 * - \%m: the month as a decimal number (range 01 to 12) 679 * - \%M: the minute as a decimal number (range 00 to 59) 680 * - \%f: the microsecond as a decimal number (range 000000 to 999999) 681 * - \%p: either "AM" or "PM" according to the given time value, or the 682 * corresponding strings for the current locale. Noon is treated as 683 * "PM" and midnight as "AM". Use of this format specifier is discouraged, as 684 * many locales have no concept of AM/PM formatting. Use \%c or \%X instead. 685 * - \%P: like \%p but lowercase: "am" or "pm" or a corresponding string for 686 * the current locale. Use of this format specifier is discouraged, as 687 * many locales have no concept of AM/PM formatting. Use \%c or \%X instead. 688 * - \%r: the time in a.m. or p.m. notation. Use of this format specifier is 689 * discouraged, as many locales have no concept of AM/PM formatting. Use \%c 690 * or \%X instead. 691 * - \%R: the time in 24-hour notation (\%H:\%M) 692 * - \%s: the number of seconds since the Epoch, that is, since 1970-01-01 693 * 00:00:00 UTC 694 * - \%S: the second as a decimal number (range 00 to 60) 695 * - \%t: a tab character 696 * - \%T: the time in 24-hour notation with seconds (\%H:\%M:\%S) 697 * - \%u: the ISO 8601 standard day of the week as a decimal, range 1 to 7, 698 * Monday being 1. This works well with \%G and \%V. 699 * - \%V: the ISO 8601 standard week number of the current year as a decimal 700 * number, range 01 to 53, where week 1 is the first week that has at 701 * least 4 days in the new year. See g_date_time_get_week_of_year(). 702 * This works well with \%G and \%u. 703 * - \%w: the day of the week as a decimal, range 0 to 6, Sunday being 0. 704 * This is not the ISO 8601 standard format -- use \%u instead. 705 * - \%x: the preferred date representation for the current locale without 706 * the time 707 * - \%X: the preferred time representation for the current locale without 708 * the date 709 * - \%y: the year as a decimal number without the century 710 * - \%Y: the year as a decimal number including the century 711 * - \%z: the time zone as an offset from UTC (+hhmm) 712 * - \%:z: the time zone as an offset from UTC (+hh:mm). 713 * This is a gnulib strftime() extension. Since: 2.38 714 * - \%::z: the time zone as an offset from UTC (+hh:mm:ss). This is a 715 * gnulib strftime() extension. Since: 2.38 716 * - \%:::z: the time zone as an offset from UTC, with : to necessary 717 * precision (e.g., -04, +05:30). This is a gnulib strftime() extension. Since: 2.38 718 * - \%Z: the time zone or name or abbreviation 719 * - \%\%: a literal \% character 720 * 721 * Some conversion specifications can be modified by preceding the 722 * conversion specifier by one or more modifier characters. The 723 * following modifiers are supported for many of the numeric 724 * conversions: 725 * 726 * - O: Use alternative numeric symbols, if the current locale supports those. 727 * - _: Pad a numeric result with spaces. This overrides the default padding 728 * for the specifier. 729 * - -: Do not pad a numeric result. This overrides the default padding 730 * for the specifier. 731 * - 0: Pad a numeric result with zeros. This overrides the default padding 732 * for the specifier. 733 * 734 * Additionally, when O is used with B, b, or h, it produces the alternative 735 * form of a month name. The alternative form should be used when the month 736 * name is used without a day number (e.g., standalone). It is required in 737 * some languages (Baltic, Slavic, Greek, and more) due to their grammatical 738 * rules. For other languages there is no difference. \%OB is a GNU and BSD 739 * strftime() extension expected to be added to the future POSIX specification, 740 * \%Ob and \%Oh are GNU strftime() extensions. Since: 2.56 741 * 742 * Params: 743 * format = a valid UTF-8 string, containing the format for the 744 * #GDateTime 745 * 746 * Returns: a newly allocated string formatted to 747 * the requested format or %NULL in the case that there was an error (such 748 * as a format specifier not being supported in the current locale). The 749 * string should be freed with g_free(). 750 * 751 * Since: 2.26 752 */ 753 public string format(string format) 754 { 755 auto retStr = g_date_time_format(gDateTime, Str.toStringz(format)); 756 757 scope(exit) Str.freeString(retStr); 758 return Str.toString(retStr); 759 } 760 761 /** 762 * Format @datetime in [ISO 8601 format](https://en.wikipedia.org/wiki/ISO_8601), 763 * including the date, time and time zone, and return that as a UTF-8 encoded 764 * string. 765 * 766 * Since GLib 2.66, this will output to sub-second precision if needed. 767 * 768 * Returns: a newly allocated string formatted in 769 * ISO 8601 format or %NULL in the case that there was an error. The string 770 * should be freed with g_free(). 771 * 772 * Since: 2.62 773 */ 774 public string formatIso8601() 775 { 776 auto retStr = g_date_time_format_iso8601(gDateTime); 777 778 scope(exit) Str.freeString(retStr); 779 return Str.toString(retStr); 780 } 781 782 /** 783 * Retrieves the day of the month represented by @datetime in the gregorian 784 * calendar. 785 * 786 * Returns: the day of the month 787 * 788 * Since: 2.26 789 */ 790 public int getDayOfMonth() 791 { 792 return g_date_time_get_day_of_month(gDateTime); 793 } 794 795 /** 796 * Retrieves the ISO 8601 day of the week on which @datetime falls (1 is 797 * Monday, 2 is Tuesday... 7 is Sunday). 798 * 799 * Returns: the day of the week 800 * 801 * Since: 2.26 802 */ 803 public int getDayOfWeek() 804 { 805 return g_date_time_get_day_of_week(gDateTime); 806 } 807 808 /** 809 * Retrieves the day of the year represented by @datetime in the Gregorian 810 * calendar. 811 * 812 * Returns: the day of the year 813 * 814 * Since: 2.26 815 */ 816 public int getDayOfYear() 817 { 818 return g_date_time_get_day_of_year(gDateTime); 819 } 820 821 /** 822 * Retrieves the hour of the day represented by @datetime 823 * 824 * Returns: the hour of the day 825 * 826 * Since: 2.26 827 */ 828 public int getHour() 829 { 830 return g_date_time_get_hour(gDateTime); 831 } 832 833 /** 834 * Retrieves the microsecond of the date represented by @datetime 835 * 836 * Returns: the microsecond of the second 837 * 838 * Since: 2.26 839 */ 840 public int getMicrosecond() 841 { 842 return g_date_time_get_microsecond(gDateTime); 843 } 844 845 /** 846 * Retrieves the minute of the hour represented by @datetime 847 * 848 * Returns: the minute of the hour 849 * 850 * Since: 2.26 851 */ 852 public int getMinute() 853 { 854 return g_date_time_get_minute(gDateTime); 855 } 856 857 /** 858 * Retrieves the month of the year represented by @datetime in the Gregorian 859 * calendar. 860 * 861 * Returns: the month represented by @datetime 862 * 863 * Since: 2.26 864 */ 865 public int getMonth() 866 { 867 return g_date_time_get_month(gDateTime); 868 } 869 870 /** 871 * Retrieves the second of the minute represented by @datetime 872 * 873 * Returns: the second represented by @datetime 874 * 875 * Since: 2.26 876 */ 877 public int getSecond() 878 { 879 return g_date_time_get_second(gDateTime); 880 } 881 882 /** 883 * Retrieves the number of seconds since the start of the last minute, 884 * including the fractional part. 885 * 886 * Returns: the number of seconds 887 * 888 * Since: 2.26 889 */ 890 public double getSeconds() 891 { 892 return g_date_time_get_seconds(gDateTime); 893 } 894 895 /** 896 * Get the time zone for this @datetime. 897 * 898 * Returns: the time zone 899 * 900 * Since: 2.58 901 */ 902 public TimeZone getTimezone() 903 { 904 auto __p = g_date_time_get_timezone(gDateTime); 905 906 if(__p is null) 907 { 908 return null; 909 } 910 911 return new TimeZone(cast(GTimeZone*) __p); 912 } 913 914 /** 915 * Determines the time zone abbreviation to be used at the time and in 916 * the time zone of @datetime. 917 * 918 * For example, in Toronto this is currently "EST" during the winter 919 * months and "EDT" during the summer months when daylight savings 920 * time is in effect. 921 * 922 * Returns: the time zone abbreviation. The returned 923 * string is owned by the #GDateTime and it should not be 924 * modified or freed 925 * 926 * Since: 2.26 927 */ 928 public string getTimezoneAbbreviation() 929 { 930 return Str.toString(g_date_time_get_timezone_abbreviation(gDateTime)); 931 } 932 933 /** 934 * Determines the offset to UTC in effect at the time and in the time 935 * zone of @datetime. 936 * 937 * The offset is the number of microseconds that you add to UTC time to 938 * arrive at local time for the time zone (ie: negative numbers for time 939 * zones west of GMT, positive numbers for east). 940 * 941 * If @datetime represents UTC time, then the offset is always zero. 942 * 943 * Returns: the number of microseconds that should be added to UTC to 944 * get the local time 945 * 946 * Since: 2.26 947 */ 948 public GTimeSpan getUtcOffset() 949 { 950 return g_date_time_get_utc_offset(gDateTime); 951 } 952 953 /** 954 * Returns the ISO 8601 week-numbering year in which the week containing 955 * @datetime falls. 956 * 957 * This function, taken together with g_date_time_get_week_of_year() and 958 * g_date_time_get_day_of_week() can be used to determine the full ISO 959 * week date on which @datetime falls. 960 * 961 * This is usually equal to the normal Gregorian year (as returned by 962 * g_date_time_get_year()), except as detailed below: 963 * 964 * For Thursday, the week-numbering year is always equal to the usual 965 * calendar year. For other days, the number is such that every day 966 * within a complete week (Monday to Sunday) is contained within the 967 * same week-numbering year. 968 * 969 * For Monday, Tuesday and Wednesday occurring near the end of the year, 970 * this may mean that the week-numbering year is one greater than the 971 * calendar year (so that these days have the same week-numbering year 972 * as the Thursday occurring early in the next year). 973 * 974 * For Friday, Saturday and Sunday occurring near the start of the year, 975 * this may mean that the week-numbering year is one less than the 976 * calendar year (so that these days have the same week-numbering year 977 * as the Thursday occurring late in the previous year). 978 * 979 * An equivalent description is that the week-numbering year is equal to 980 * the calendar year containing the majority of the days in the current 981 * week (Monday to Sunday). 982 * 983 * Note that January 1 0001 in the proleptic Gregorian calendar is a 984 * Monday, so this function never returns 0. 985 * 986 * Returns: the ISO 8601 week-numbering year for @datetime 987 * 988 * Since: 2.26 989 */ 990 public int getWeekNumberingYear() 991 { 992 return g_date_time_get_week_numbering_year(gDateTime); 993 } 994 995 /** 996 * Returns the ISO 8601 week number for the week containing @datetime. 997 * The ISO 8601 week number is the same for every day of the week (from 998 * Moday through Sunday). That can produce some unusual results 999 * (described below). 1000 * 1001 * The first week of the year is week 1. This is the week that contains 1002 * the first Thursday of the year. Equivalently, this is the first week 1003 * that has more than 4 of its days falling within the calendar year. 1004 * 1005 * The value 0 is never returned by this function. Days contained 1006 * within a year but occurring before the first ISO 8601 week of that 1007 * year are considered as being contained in the last week of the 1008 * previous year. Similarly, the final days of a calendar year may be 1009 * considered as being part of the first ISO 8601 week of the next year 1010 * if 4 or more days of that week are contained within the new year. 1011 * 1012 * Returns: the ISO 8601 week number for @datetime. 1013 * 1014 * Since: 2.26 1015 */ 1016 public int getWeekOfYear() 1017 { 1018 return g_date_time_get_week_of_year(gDateTime); 1019 } 1020 1021 /** 1022 * Retrieves the year represented by @datetime in the Gregorian calendar. 1023 * 1024 * Returns: the year represented by @datetime 1025 * 1026 * Since: 2.26 1027 */ 1028 public int getYear() 1029 { 1030 return g_date_time_get_year(gDateTime); 1031 } 1032 1033 /** 1034 * Retrieves the Gregorian day, month, and year of a given #GDateTime. 1035 * 1036 * Params: 1037 * year = the return location for the gregorian year, or %NULL. 1038 * month = the return location for the month of the year, or %NULL. 1039 * day = the return location for the day of the month, or %NULL. 1040 * 1041 * Since: 2.26 1042 */ 1043 public void getYmd(out int year, out int month, out int day) 1044 { 1045 g_date_time_get_ymd(gDateTime, &year, &month, &day); 1046 } 1047 1048 /** 1049 * Determines if daylight savings time is in effect at the time and in 1050 * the time zone of @datetime. 1051 * 1052 * Returns: %TRUE if daylight savings time is in effect 1053 * 1054 * Since: 2.26 1055 */ 1056 public bool isDaylightSavings() 1057 { 1058 return g_date_time_is_daylight_savings(gDateTime) != 0; 1059 } 1060 1061 alias doref = ref_; 1062 /** 1063 * Atomically increments the reference count of @datetime by one. 1064 * 1065 * Returns: the #GDateTime with the reference count increased 1066 * 1067 * Since: 2.26 1068 */ 1069 public DateTime ref_() 1070 { 1071 auto __p = g_date_time_ref(gDateTime); 1072 1073 if(__p is null) 1074 { 1075 return null; 1076 } 1077 1078 return new DateTime(cast(GDateTime*) __p, true); 1079 } 1080 1081 /** 1082 * Creates a new #GDateTime corresponding to the same instant in time as 1083 * @datetime, but in the local time zone. 1084 * 1085 * This call is equivalent to calling g_date_time_to_timezone() with the 1086 * time zone returned by g_time_zone_new_local(). 1087 * 1088 * Returns: the newly created #GDateTime which 1089 * should be freed with g_date_time_unref(), or %NULL 1090 * 1091 * Since: 2.26 1092 */ 1093 public DateTime toLocal() 1094 { 1095 auto __p = g_date_time_to_local(gDateTime); 1096 1097 if(__p is null) 1098 { 1099 return null; 1100 } 1101 1102 return new DateTime(cast(GDateTime*) __p, true); 1103 } 1104 1105 /** 1106 * Stores the instant in time that @datetime represents into @tv. 1107 * 1108 * The time contained in a #GTimeVal is always stored in the form of 1109 * seconds elapsed since 1970-01-01 00:00:00 UTC, regardless of the time 1110 * zone associated with @datetime. 1111 * 1112 * On systems where 'long' is 32bit (ie: all 32bit systems and all 1113 * Windows systems), a #GTimeVal is incapable of storing the entire 1114 * range of values that #GDateTime is capable of expressing. On those 1115 * systems, this function returns %FALSE to indicate that the time is 1116 * out of range. 1117 * 1118 * On systems where 'long' is 64bit, this function never fails. 1119 * 1120 * Deprecated: #GTimeVal is not year-2038-safe. Use 1121 * g_date_time_to_unix() instead. 1122 * 1123 * Params: 1124 * tv = a #GTimeVal to modify 1125 * 1126 * Returns: %TRUE if successful, else %FALSE 1127 * 1128 * Since: 2.26 1129 */ 1130 public bool toTimeval(TimeVal tv) 1131 { 1132 return g_date_time_to_timeval(gDateTime, (tv is null) ? null : tv.getTimeValStruct()) != 0; 1133 } 1134 1135 /** 1136 * Create a new #GDateTime corresponding to the same instant in time as 1137 * @datetime, but in the time zone @tz. 1138 * 1139 * This call can fail in the case that the time goes out of bounds. For 1140 * example, converting 0001-01-01 00:00:00 UTC to a time zone west of 1141 * Greenwich will fail (due to the year 0 being out of range). 1142 * 1143 * Params: 1144 * tz = the new #GTimeZone 1145 * 1146 * Returns: the newly created #GDateTime which 1147 * should be freed with g_date_time_unref(), or %NULL 1148 * 1149 * Since: 2.26 1150 */ 1151 public DateTime toTimezone(TimeZone tz) 1152 { 1153 auto __p = g_date_time_to_timezone(gDateTime, (tz is null) ? null : tz.getTimeZoneStruct()); 1154 1155 if(__p is null) 1156 { 1157 return null; 1158 } 1159 1160 return new DateTime(cast(GDateTime*) __p, true); 1161 } 1162 1163 /** 1164 * Gives the Unix time corresponding to @datetime, rounding down to the 1165 * nearest second. 1166 * 1167 * Unix time is the number of seconds that have elapsed since 1970-01-01 1168 * 00:00:00 UTC, regardless of the time zone associated with @datetime. 1169 * 1170 * Returns: the Unix time corresponding to @datetime 1171 * 1172 * Since: 2.26 1173 */ 1174 public long toUnix() 1175 { 1176 return g_date_time_to_unix(gDateTime); 1177 } 1178 1179 /** 1180 * Creates a new #GDateTime corresponding to the same instant in time as 1181 * @datetime, but in UTC. 1182 * 1183 * This call is equivalent to calling g_date_time_to_timezone() with the 1184 * time zone returned by g_time_zone_new_utc(). 1185 * 1186 * Returns: the newly created #GDateTime which 1187 * should be freed with g_date_time_unref(), or %NULL 1188 * 1189 * Since: 2.26 1190 */ 1191 public DateTime toUtc() 1192 { 1193 auto __p = g_date_time_to_utc(gDateTime); 1194 1195 if(__p is null) 1196 { 1197 return null; 1198 } 1199 1200 return new DateTime(cast(GDateTime*) __p, true); 1201 } 1202 1203 /** 1204 * Atomically decrements the reference count of @datetime by one. 1205 * 1206 * When the reference count reaches zero, the resources allocated by 1207 * @datetime are freed 1208 * 1209 * Since: 2.26 1210 */ 1211 public void unref() 1212 { 1213 g_date_time_unref(gDateTime); 1214 } 1215 }